package java51_0607;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Scanner;

//1：实现文件复制的功能，通过命令行参数，输入一个源文件名，和目标文件夹，复制后文件名保持不变。
//比如 文件名是d:\mypicture\1.jpg,目标文件夹是 e:\mydoc\，则复制后文件夹e:\mydoc将会出现1.jpg.

public class CopydriTest {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.print("请输入文件名：");
		String s1 = sc.next();
		System.out.print("请目标文件夹：");
		String s2 = sc.next();

		File f1 = new File(s1);
		File f2 = new File(s2, f1.getName());

		FileInputStream fo = null;
		FileOutputStream fi = null;

		try {
			fo = new FileInputStream(f1);
			byte b[] = new byte[50];
			fi = new FileOutputStream(f2);
			int len = 0;
			while ((len = fo.read(b)) > -1) {
				String s = new String(b, 0, len);
				fi.write(b);
			}
			System.out.println("复制完成！！！");
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (fo != null)
					fo.close();
				if (fi != null)
					fi.close();
			} catch (Exception e) {
				e.printStackTrace();
			}

		}

	}
}
